<template>
	<div class="components-container">
        <!-- 新增/修改 -->
        <sweet-modal ref="dialog" class="dialog">
          <h3>{{title}}</h3>
            <div style=" height:200px; margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">区域名称</label>
                        <div class="layui-input-inline" style="width:455px;">
                            <el-input v-model="ashesAreaData.ASANAME" placeholder="请输入区域名称"></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">横项总数</label>
                        <div class="layui-input-inline">
                            <el-input-number v-model="ashesAreaData.ASAXCOUNT" :min="1" :max="xMax"></el-input-number>
                        </div>
                        <label class="layui-form-label">纵项总数</label>
                        <div class="layui-input-inline">
                            <el-input-number v-model="ashesAreaData.ASAYCOUNT" :min="1" :max="yMax"></el-input-number>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="this.isshowarea">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="text-align:center">区域开始编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesAreaData.ASASTARTNUM"></el-input>
                        </div>
                        <label class="layui-form-label" style="text-align:center">区域结束编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesAreaData.ASAENDNUM"></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="this.isshowarea">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="text-align:center">序号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesAreaData.ASASORT"></el-input>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
                <el-button type="primary" @click="submit" :loading="this.$store.state.isloading">确定</el-button>
            </div>
        </sweet-modal>
        <!-- 详情 -->
        <sweet-modal ref="dialogInfo" class="dialog">
          <h3>{{title}}</h3>
            <div style=" height:200px; margin:30px 50px">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">区域名称</label>
                        <div class="layui-input-inline" style="width:465px;">
                            <el-input v-model="ashesAreaData.ASANAME" placeholder="请输入区域名称" readonly></el-input>
                        </div>
                    </div>
                </div>
                 <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">横项总数</label>
                        <div class="layui-input-inline">
                          <el-input v-model="ashesAreaData.ASAXCOUNT" placeholder="请输入区域名称" readonly></el-input>
                        </div>
                        <label class="layui-form-label">纵项总数</label>
                        <div class="layui-input-inline">
                          <el-input v-model="ashesAreaData.ASAYCOUNT" placeholder="请输入区域名称" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="this.isshowarea">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="text-align:center">区域开始编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesAreaData.ASASTARTNUM" readonly></el-input>
                        </div>
                        <label class="layui-form-label" style="text-align:center">区域结束编号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesAreaData.ASAENDNUM" readonly></el-input>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" v-if="this.isshowarea">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="text-align:center">序号</label>
                        <div class="layui-input-inline">
                            <el-input v-model="ashesAreaData.ASASORT" readonly></el-input>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item btnCenter">
                <el-button @click="closeDialog">取消</el-button>
            </div>
        </sweet-modal>
	</div>

</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btn {
  text-align: center;
}
</style>
<script>
import sweetModal from "@/components/sweetModal";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";

export default {
  name: "ashesAreaMain",
  props: {
    orderType: {
      type: String,
      default() {
        return ADD;
      }
    }
  },
  data() {
    return {
      title: null,
      loading: false,

      ashesAreaData: {},

      isshowarea: null,

      xMax: 100,
      yMax: 100
    };
  },
  methods: {
    //区域查询
    getData() {
      let data = {
        PageIndex: this.pageOrder.currentPage,
        PageSize: this.pageOrder.pageSize,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: JSON.parse(JSON.stringify(this.selectData))
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashesarea.Query,
        res => {
          this.dataList = res.data.content.OutData;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //获取坐标最大值
    getMaxValue() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashesarea.MaxValue,
        res => {
          this.xMax = parseInt(res.data.content[0].Value);
          this.yMax = parseInt(res.data.content[1].Value);
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //新增寄存堂区域是否显示区域开始编号和结束编号
    getIsshowarea() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Param.GetIsShowAddAsaRegionNum,
        res => {
         this.isshowarea = res.data.content;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //功能操作
    open(order, id) {
      this.order = order;
      //清理数据
      this.dataRepeat();
      switch (this.order) {
        case ADD:
          this.title = "寄存区域新增";
          this.initSelectData();
          this.$refs.dialog.open();
          break;
        case MODIFY:
          this.title = "寄存区域修改";
          this.initSelectData();
          this.dataInfo(id);
          this.$refs.dialog.open();
          break;
        case DELETE:
          this.dataDelete(id);
          break;
        case INFO:
          this.title = "寄存区域详情";
          this.dataInfo(id);
          this.$refs.dialogInfo.open();
          break;
        default:
      }
    },
    //提交
    submit() {
      this.$store.state.isloading = true;
      switch (this.order) {
        case ADD:
          this.dataAdd();
          break;
        case MODIFY:
          this.dataModify();
          break;
        case DELETE:
          break;
        case INFO:
          this.$refs.dialogInfo.close();
          break;
        default:
      }
    },
    //区域新增
    dataAdd() {
      let data = JSON.parse(JSON.stringify(this.ashesAreaData));
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashesarea.Create,
        res => {
          this.refreshData();
          this.$refs.dialog.close();
          this.$message({
            message: this.order + res.data.msg,
            type: "success"
          });
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //区域修改
    dataModify() {
      let data = JSON.parse(JSON.stringify(this.ashesAreaData));
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashesarea.Modify,
        res => {
          this.refreshData();
          this.$refs.dialog.close();
          this.$message({
            message: this.order + res.data.msg,
            type: "success"
          });
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //区域删除
    dataDelete(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(callback => {
        var data = {
          ASAID: id
        };
        apiBase.DoService(
          data,
          apiBase.getApiAdress().Ashesarea.Delete,
          res => {
            this.refreshData();
            this.$message({
              message: this.order + res.data.msg,
              type: "success"
            });
          },
          res => {
            this.$message.error(res.data.msg);
          }
        );
      });
    },
    //区域详情
    dataInfo(id) {
      var data = {
        ASAID: id
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Ashesarea.Detail,
        res => {
          this.ashesAreaData = res.data.content;
          this.ashesAreaData.ASAID = id;
        },
        res => {
          this.$message.error(res.data.msg);
        }
      );
    },
    //数据重置
    dataRepeat() {
      this.ashesAreaData = {};
    },
    //初始化下拉框数据
    initSelectData() {
      this.getMaxValue();
    },
    refreshData() {
      this.$emit("refreshData");
    },
    closeDialog() {
      if (this.order === ADD || this.order === MODIFY)
        this.$refs.dialog.close();
      else if (this.order === INFO) this.$refs.dialogInfo.close();
    }
  },
  components: {
    sweetModal
  },
  mounted() {},
  created() {
    this.getIsshowarea();
  }
};
</script>